<?php

namespace App\Models\SiteLocation;

use App\Models\BaseModel;
use App\Models\Kms\User\KmsUser;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class SiteLocationWhiteListModel extends BaseModel
{
    protected $table = 'site_location_white_list';

    protected $fillable = [
        'id',
        'rmsUserId',
        'appPower',
        'pcPower',
        'status',
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
    ];

    protected $appends = [
        'statusText',
    ];

    /**
     * 用户状态
     */
    const STATUS_ON      = 0;
    const STATUS_OFF     = 1;
    const STATUS_MAPPING = [
        self::STATUS_ON  => '启用',
        self::STATUS_OFF => '停用',
    ];

    /**
     * 网规权限类型
     */
    const POWER_TYPE_APP = 1;
    const POWER_TYPE_PC  = 2;
    const POWER_TYPES    = [
        self::POWER_TYPE_APP => 'APP',
        self::POWER_TYPE_PC  => 'PC',
    ];


    /**
     * 状态访问起
     * @return string
     */
    public function getStatusTextAttribute(): string
    {
        return self::STATUS_MAPPING[$this->getAttribute('status')] ?? '';
    }

    /**
     * 关联 kf_fs_user
     * 一对一?
     */
    public function kfFsUserRel(): HasOne
    {
        return $this->hasOne(KmsUser::class, 'rmsUserId', 'rmsUserId');
    }


}